import {nav} from "@/micro/nav/nav";
import {publicAssets} from "@/micro/publicAssets";
import {designMainApplication, NavType} from "plain-micro-application";
import {registryBasePages} from "../pages/registryBasePages";
import {registryUmiPages} from "../pages/registryUmiPages";

function registryReactPages(nav: NavType) {
    nav.micro.registry({
        name: 'React子应用模块',
        type: 'React',
        url: (process.env.NODE_ENV === 'production' ? 'http://martsforever-demo.gitee.io' : 'http://localhost:3122') + '/template-plain-react-micro-sub-react/',
        pattern: [
            'sub-react',
        ],
    });
    nav.micro.registry({
        name: 'React Vite子应用模块',
        type: 'React',
        // url: 'http://martsforever-demo.gitee.io/template-plain-react-micro-sub-react/',
        url: (process.env.NODE_ENV === 'production' ? 'http://martsforever-demo.gitee.io' : 'http://localhost:3124') + '/template-plain-react-micro-sub-react-vite/',
        // url: 'http://localhost:5000',
        pattern: [
            'sub-react-vite',
        ],
    })
    nav.micro.registry({
        name: 'React Router子应用模块',
        type: 'React',
        // url: 'http://martsforever-demo.gitee.io/template-plain-react-micro-sub-react/',
        url: (process.env.NODE_ENV === 'production' ? 'http://martsforever-demo.gitee.io' : 'http://localhost:3131') + '/temp-cra-reactrouter/micro.html',
        // url: 'http://localhost:5000',
        pattern: [
            'sub-router-react',
        ],
    })
}

function registryVuePages(nav: NavType) {
    nav.micro.registry({
        name: 'Vue子应用模块',
        type: 'Vue3',
        // url: 'http://martsforever-demo.gitee.io/template-plain-react-micro-sub-vue/',
        url: (process.env.NODE_ENV === 'production' ? 'http://martsforever-demo.gitee.io' : 'http://localhost:3123') + '/template-plain-react-micro-sub-vue/',
        pattern: [
            'sub-vue',
        ],
    })
    nav.micro.registry({
        name: 'Vue Vite子应用模块',
        type: 'Vue3',
        // url: 'http://martsforever-demo.gitee.io/template-plain-react-micro-sub-react/',
        url: (process.env.NODE_ENV === 'production' ? 'http://martsforever-demo.gitee.io' : 'http://localhost:3125') + '/template-plain-react-micro-sub-vue-vite/',
        // url: 'http://localhost:5000',
        pattern: [
            'sub-vue-vite',
        ],
    })
    nav.micro.registry({
        name: 'Vue3 Router子应用模块',
        type: 'Vue3',
        // url: 'http://martsforever-demo.gitee.io/template-plain-react-micro-sub-react/',
        url: (process.env.NODE_ENV === 'production' ? 'http://martsforever-demo.gitee.io' : 'http://localhost:3130') + '/temp-vuecli-vuerouter/micro.html',
        // url: 'http://localhost:5000',
        pattern: [
            'sub-router-vue',
        ],
    })
}

/**
 * 单应用模式，只有一个BASE工程
 * @author  韦胜健
 * @date    2021/5/7 16:55
 */
export default designMainApplication({
    getPublicPath: () => __webpack_public_path__,
    setPublicPath: (path) => __webpack_public_path__ = path,
    init: (beforeInitMainApplication) => {

        registryBasePages(nav);
        registryReactPages(nav);
        registryVuePages(nav);
        registryUmiPages(nav);

        (async () => {
            !!beforeInitMainApplication && await beforeInitMainApplication(nav)
            await publicAssets.initManagerApplication({
                publicPath: __webpack_public_path__,
                data: {},
            })
        })()
        return {
            publicAssets,
            nav,
        }
    }
})
